package com.aaa.controller;

import com.aaa.common.domain.RenterInfo;
import com.aaa.common.query.RenterInfoQuery;
import com.aaa.common.result.Result;
import com.aaa.service.impl.RenterInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/renter")
public class RenterInfoController {

    @Autowired
    private RenterInfoServiceImpl service;

    /**
     * 查询单位租户
     */
    @PostMapping("/listU")
    public Result listUnitRenter(@RequestBody RenterInfoQuery renterQuery){
        Result result = service.listUnitRenter(renterQuery);
        System.out.println(result);
        return result;
    }

    /**
     * 查询个人租户
     */
    @PostMapping("/listP")
    public Result listPersonRenter(@RequestBody RenterInfoQuery renterQuery){
        Result result = service.listPersonalRenter(renterQuery);
        System.out.println(result);
        return result;
    }

    /**
     * 下拉框
     * @return
     */
    @GetMapping("select")
    public Result listSel(){
        Result result = service.listMark();
        return result;
    }

    /**
     * 添加租户
     * @return
     */
    @PostMapping("/add")
    public Result addPersonRenter(@RequestBody RenterInfo renterInfo){
        boolean b = service.addPersonalRenter(renterInfo);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    /**
     * 修改租户
     * @return
     */
    @PostMapping("/update")
    public Result updatePersonRenter(@RequestBody RenterInfo renterInfo){
        boolean b = service.updatePersonalRenter(renterInfo);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    /**
     * 通过id查询该数据
     * @param id
     * @return
     */
    @GetMapping("getId")
    public Result getId(Integer id){
        Result result = service.listPersonalRenterById(id);
        return result;
    }


    /**
     * 删除租户
     * @return
     */
    @DeleteMapping("/delete")
    public Result delPersonRenter(String ids){
        boolean b = service.deletePersonalRenter(ids);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }



//    /**
//     * 查询单位租户
//     */
//    @GetMapping("/listU")
//    public Result listUnitRenter(RenterQuery renterQuery){
//        Result renter = service.listUnitRenter(renterQuery);
//        return Result.success(renter);
//    }
}
